/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.backstage;

import java.sql.Date;

/**
 *
 * @author Guilherme
 */
public class Data
{
    private int dia;
    private int mes;
    private int ano;

    public Data (int i, int j, int k)
    {
        if ((i > 0 && i < 32) && (j > 0  && j < 13) && (k > 0))
        {
        this.dia = i;
        this.mes = j;
        this.ano = k;
        }
    }
    
    public Data (Date d)
    {
        this.dia = d.getDay();
        this.mes = d.getMonth();
        this.ano = d.getYear();
    }
    
    public Data (String s)
    {
        String[] ts = new String[3];
        int i, j, k;
        for (k = 0, i = 0; i < s.length(); i = j + 1, k++)
        {
            for (j = i; j < s.length() && s.charAt(j) != '-'; j++);
            ts[k] = s.substring(i, j);
        }
        this.ano = Integer.parseInt(ts[0]);
        this.mes = Integer.parseInt(ts[1]);
        this.dia = Integer.parseInt(ts[2]);    
    }
    
    public void soma7 ()
    {
        if (this.mesTem31(this.mes))
        {
            this.dia = (this.dia + 7) % 31;
            this.mes = (this.mes + 1) % 12;
        }
        if (this.mesTem30(this.mes))
        {
            this.dia = (this.dia + 7) % 30;
            this.mes = (this.mes + 1) % 12;
        }
        else
        {
            this.dia = (this.dia + 7) % 28;
            this.mes = (this.mes + 1) % 12;
        }
    }
    
    private boolean mesTem31 (int i)
    {
        if (i == 2)
            return false;
        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
            return true;
        return false;
    }
    
    private boolean mesTem30 (int i)
    {
        if (!this.mesFev(i) && !this.mesTem31(i))
            return true;
        else
            return false;
    }
    
    private boolean mesFev (int i)
    {
        if (i == 2)
            return true;
        else
            return false;
    }
    
    public String toString()
    {
        return this.ano+"-"+this.mes+"-"+this.dia;
    }
    
    
}
